/*******************************************************************************
 * Copyright (c) 2009-2011 ETCORE Labs. All rights reserved. 
 * 
 * This software is the confidential and proprietary information of ETCORE Labs.
 * You shall not disclose such confidential information and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with ETCORE Labs. 
 * 
 * Support can be obtained from support forums at:  http://www.etcore.com/
 * /
 *******************************************************************************/
package etcore.webapp.grouptalk.common.service;

import java.util.List;

import org.hibernate.Session;

import etcore.webapp.grouptalk.common.dao.HibernateSessionFactory;
import etcore.webapp.grouptalk.common.dao.ReplyTemplateDAO;
import etcore.webapp.grouptalk.common.object.ReplyTemplate;

/**
 * ReplyTemplateService implements queries and transactions on ReplyTemplate
 * 
 * @author ETCORE GroupTalk Developers
 * 
 */
public class ReplyTemplateService extends BaseService {
	/**
	 * Find ReplyTemplate instances
	 * 
	 * @param begin
	 *            start position
	 * @param length
	 *            count of instances
	 * @return ReplyTemplate instances
	 */
	public List<ReplyTemplate> findAll(int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			ReplyTemplateDAO dao = new ReplyTemplateDAO();
			List<ReplyTemplate> result = dao.findAll(begin, length);
			return result;

		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	/**
	 * Get ReplyTemplate instance by id
	 * 
	 * @param id
	 *            instance id
	 * @return ReplyTemplate instance
	 */
	public ReplyTemplate findById(java.lang.Integer id) {
		Session session = HibernateSessionFactory.getSession();
		try {
			ReplyTemplateDAO dao = new ReplyTemplateDAO();
			ReplyTemplate result = dao.findById(id);
			return result;

		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	/**
	 * Find instances of ReplyTemplate by a property value
	 * 
	 * @param propertyName
	 *            property name
	 * @param value
	 *            property value
	 * @return ReplyTemplate instances
	 */
	public List<ReplyTemplate> findByProperty(String propertyName, Object value) {
		Session session = HibernateSessionFactory.getSession();
		try {
			ReplyTemplateDAO dao = new ReplyTemplateDAO();
			List<ReplyTemplate> result = dao
					.findByProperty(propertyName, value);
			return result;

		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public List<ReplyTemplate> findByCommonAndTid(Integer tid, int begin,
			int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			ReplyTemplateDAO dao = new ReplyTemplateDAO();
			List<ReplyTemplate> result = dao.findByCommonAndTid(tid, begin,
					length);
			return result;

		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	/**
	 * Find instances of ReplyTemplate by a property value
	 * 
	 * @param propertyName
	 *            property name
	 * @param value
	 *            property value
	 * @param begin
	 *            start position
	 * @param length
	 *            count of instances
	 * @return ReplyTemplate instances
	 */
	public List<ReplyTemplate> findByProperty(String propertyName,
			Object value, int begin, int length) {
		Session session = HibernateSessionFactory.getSession();
		try {
			ReplyTemplateDAO dao = new ReplyTemplateDAO();
			List<ReplyTemplate> result = dao.findByProperty(propertyName,
					value, begin, length);
			return result;

		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	/**
	 * Find the count of ReplyTemplate instances by a property value
	 * 
	 * @param propertyName
	 *            property name
	 * @param value
	 *            property value
	 * @return the count of Attachment instances
	 */
	public long findSizeByProperty(String propertyName, Object value) {
		Session session = HibernateSessionFactory.getSession();
		try {
			ReplyTemplateDAO dao = new ReplyTemplateDAO();
			long result = dao.findSizeByProperty(propertyName, value);
			return result;

		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}
	public long findSize() {
		Session session = HibernateSessionFactory.getSession();
		try {
			ReplyTemplateDAO dao = new ReplyTemplateDAO();
			long result = dao.findSize();
			return result;

		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

	public long findSizeByCommonAndTid(Integer tid) {
		Session session = HibernateSessionFactory.getSession();
		try {
			ReplyTemplateDAO dao = new ReplyTemplateDAO();
			long result = dao.findSizeByCommonAndTid(tid);
			return result;

		} catch (RuntimeException re) {

			throw re;
		} finally {
			if (session != null)
				session.close();
		}

	}

}